
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Idea_InvestmentCategory]') AND parent_object_id = OBJECT_ID(N'[dbo].[Idea]'))
ALTER TABLE [dbo].[Idea]  WITH CHECK ADD  CONSTRAINT [FK_Idea_InvestmentCategory] FOREIGN KEY([CategoryId])
REFERENCES [dbo].[InvestmentCategory] ([CategoryId])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Idea_InvestmentCategory]') AND parent_object_id = OBJECT_ID(N'[dbo].[Idea]'))
ALTER TABLE [dbo].[Idea] CHECK CONSTRAINT [FK_Idea_InvestmentCategory]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Idea_Owner]') AND parent_object_id = OBJECT_ID(N'[dbo].[Idea]'))
ALTER TABLE [dbo].[Idea]  WITH CHECK ADD  CONSTRAINT [FK_Idea_Owner] FOREIGN KEY([SubmittedBy])
REFERENCES [dbo].[UserProfile] ([UserName])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Idea_Owner]') AND parent_object_id = OBJECT_ID(N'[dbo].[Idea]'))
ALTER TABLE [dbo].[Idea] CHECK CONSTRAINT [FK_Idea_Owner]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_IdeaRating_Idea]') AND parent_object_id = OBJECT_ID(N'[dbo].[IdeaRating]'))
ALTER TABLE [dbo].[IdeaRating]  WITH CHECK ADD  CONSTRAINT [FK_IdeaRating_Idea] FOREIGN KEY([IdeaId])
REFERENCES [dbo].[Idea] ([IdeaId])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_IdeaRating_Idea]') AND parent_object_id = OBJECT_ID(N'[dbo].[IdeaRating]'))
ALTER TABLE [dbo].[IdeaRating] CHECK CONSTRAINT [FK_IdeaRating_Idea]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_IdeaRating_User]') AND parent_object_id = OBJECT_ID(N'[dbo].[IdeaRating]'))
ALTER TABLE [dbo].[IdeaRating]  WITH CHECK ADD  CONSTRAINT [FK_IdeaRating_User] FOREIGN KEY([UserName])
REFERENCES [dbo].[UserProfile] ([UserName])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_IdeaRating_User]') AND parent_object_id = OBJECT_ID(N'[dbo].[IdeaRating]'))
ALTER TABLE [dbo].[IdeaRating] CHECK CONSTRAINT [FK_IdeaRating_User]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Project_InvestmentCategory]') AND parent_object_id = OBJECT_ID(N'[dbo].[Project]'))
ALTER TABLE [dbo].[Project]  WITH CHECK ADD  CONSTRAINT [FK_Project_InvestmentCategory] FOREIGN KEY([CategoryId])
REFERENCES [dbo].[InvestmentCategory] ([CategoryId])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Project_InvestmentCategory]') AND parent_object_id = OBJECT_ID(N'[dbo].[Project]'))
ALTER TABLE [dbo].[Project] CHECK CONSTRAINT [FK_Project_InvestmentCategory]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Project_ProjectManager]') AND parent_object_id = OBJECT_ID(N'[dbo].[Project]'))
ALTER TABLE [dbo].[Project]  WITH CHECK ADD  CONSTRAINT [FK_Project_ProjectManager] FOREIGN KEY([ProjectManager])
REFERENCES [dbo].[UserProfile] ([UserName])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Project_ProjectManager]') AND parent_object_id = OBJECT_ID(N'[dbo].[Project]'))
ALTER TABLE [dbo].[Project] CHECK CONSTRAINT [FK_Project_ProjectManager]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectIdea_Idea]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectIdea]'))
ALTER TABLE [dbo].[ProjectIdea]  WITH CHECK ADD  CONSTRAINT [FK_ProjectIdea_Idea] FOREIGN KEY([IdeaId])
REFERENCES [dbo].[Idea] ([IdeaId])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectIdea_Idea]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectIdea]'))
ALTER TABLE [dbo].[ProjectIdea] CHECK CONSTRAINT [FK_ProjectIdea_Idea]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectIdea_Project]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectIdea]'))
ALTER TABLE [dbo].[ProjectIdea]  WITH CHECK ADD  CONSTRAINT [FK_ProjectIdea_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([ProjectId])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectIdea_Project]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectIdea]'))
ALTER TABLE [dbo].[ProjectIdea] CHECK CONSTRAINT [FK_ProjectIdea_Project]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectRating_Project]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectRating]'))
ALTER TABLE [dbo].[ProjectRating]  WITH CHECK ADD  CONSTRAINT [FK_ProjectRating_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([ProjectId])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectRating_Project]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectRating]'))
ALTER TABLE [dbo].[ProjectRating] CHECK CONSTRAINT [FK_ProjectRating_Project]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectRating_User]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectRating]'))
ALTER TABLE [dbo].[ProjectRating]  WITH CHECK ADD  CONSTRAINT [FK_ProjectRating_User] FOREIGN KEY([UserName])
REFERENCES [dbo].[UserProfile] ([UserName])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ProjectRating_User]') AND parent_object_id = OBJECT_ID(N'[dbo].[ProjectRating]'))
ALTER TABLE [dbo].[ProjectRating] CHECK CONSTRAINT [FK_ProjectRating_User]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_UserInterest_InvestmentCategory]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserInterest]'))
ALTER TABLE [dbo].[UserInterest]  WITH CHECK ADD  CONSTRAINT [FK_UserInterest_InvestmentCategory] FOREIGN KEY([CategoryId])
REFERENCES [dbo].[InvestmentCategory] ([CategoryId])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_UserInterest_InvestmentCategory]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserInterest]'))
ALTER TABLE [dbo].[UserInterest] CHECK CONSTRAINT [FK_UserInterest_InvestmentCategory]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_UserInterest_User]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserInterest]'))
ALTER TABLE [dbo].[UserInterest]  WITH CHECK ADD  CONSTRAINT [FK_UserInterest_User] FOREIGN KEY([UserName])
REFERENCES [dbo].[UserProfile] ([UserName])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_UserInterest_User]') AND parent_object_id = OBJECT_ID(N'[dbo].[UserInterest]'))
ALTER TABLE [dbo].[UserInterest] CHECK CONSTRAINT [FK_UserInterest_User]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Volunteer_Project]') AND parent_object_id = OBJECT_ID(N'[dbo].[Volunteer]'))
ALTER TABLE [dbo].[Volunteer]  WITH CHECK ADD  CONSTRAINT [FK_Volunteer_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([ProjectId])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Volunteer_Project]') AND parent_object_id = OBJECT_ID(N'[dbo].[Volunteer]'))
ALTER TABLE [dbo].[Volunteer] CHECK CONSTRAINT [FK_Volunteer_Project]

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Volunteer_User]') AND parent_object_id = OBJECT_ID(N'[dbo].[Volunteer]'))
ALTER TABLE [dbo].[Volunteer]  WITH CHECK ADD  CONSTRAINT [FK_Volunteer_User] FOREIGN KEY([UserName])
REFERENCES [dbo].[UserProfile] ([UserName])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Volunteer_User]') AND parent_object_id = OBJECT_ID(N'[dbo].[Volunteer]'))
ALTER TABLE [dbo].[Volunteer] CHECK CONSTRAINT [FK_Volunteer_User]

GO
